﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using GroupManager.Resource.CSDL;
namespace GroupManager.Class
{
    public class LopAlbum
    {
        // Kiểm tra Album
        public static bool KiemTraAlbum(int maab)
        {
            dbGroupManagerDataContext db = new dbGroupManagerDataContext();
            if (db.Albums.Where(q => q.MaAlbum == maab).Count() != 0)
                return true;
            return false;
        }
        //Thêm Album
        public static void ThemAlbum(string TenAlbum, int madnh, int anh)
        {
            dbGroupManagerDataContext db = new dbGroupManagerDataContext();
            Album ab = new Album();
            ab.TenAlbum = TenAlbum;
            ab.MaDoiNhom = madnh;
            ab.AnhDaiDien = anh;
            db.Albums.InsertOnSubmit(ab);
            db.SubmitChanges();
        }

        //Xóa Album
        public static void XoaAlbum(int MaAlbum)
        {
            dbGroupManagerDataContext db = new dbGroupManagerDataContext();
            Album ab = db.Albums.FirstOrDefault(q => q.MaAlbum == MaAlbum);
            db.Albums.DeleteOnSubmit(ab);
            db.SubmitChanges();
        }

        //Chọn ảnh đại diện cho Album
        public static void ChonDaiDien(int MaAlbum, int AnhDaiDien)
        {
            dbGroupManagerDataContext db = new dbGroupManagerDataContext();
            Album ab = db.Albums.SingleOrDefault(q => q.MaAlbum == MaAlbum);
            ab.AnhDaiDien = AnhDaiDien;
            db.SubmitChanges();
        }

        // Sửa tên Album
        public static void SuaTenAlbum(int maab, string tenalbum)
        {
            dbGroupManagerDataContext db = new dbGroupManagerDataContext();
            Album ab = db.Albums.SingleOrDefault(q => q.MaAlbum == maab);
            ab.TenAlbum = tenalbum;
            db.SubmitChanges();
        }

        // Lấy tất cả ảnh thuộc Album
        public static IQueryable<Resource.CSDL.Anh> LayAnhAlbum(int maab)
        {
            dbGroupManagerDataContext db = new dbGroupManagerDataContext();
            var sql = db.Anhs.Where(q => q.MaAlbum == maab);
            return sql;
        }

        // Lấy tên Album
        public static Album LayTenAlbum(int maab)
        {
            dbGroupManagerDataContext db = new dbGroupManagerDataContext();
            Album ab = db.Albums.SingleOrDefault(q => q.MaAlbum == maab);
            return ab;
        }
    }
}